package com.sxpcwlkj.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sxpcwlkj.common.code.controller.BaseController;
import com.sxpcwlkj.common.utils.AjaxResult;
import com.sxpcwlkj.framework.entity.page.PageQuery;
import com.sxpcwlkj.framework.entity.page.TableDataInfo;
import com.sxpcwlkj.system.entity.bo.SysDictBo;
import com.sxpcwlkj.system.entity.bo.SysRoleBo;
import com.sxpcwlkj.system.entity.vo.SysDictVo;
import com.sxpcwlkj.system.entity.vo.SysRoleVo;
import com.sxpcwlkj.system.service.SysDictService;
import com.sxpcwlkj.system.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author sxpcwlkj
 * @Version v1.0.0
 */
@RequestMapping("system/dict")
@RestController
@RequiredArgsConstructor
public class SysDictController extends BaseController {


    private final SysDictService baseService;


    /**
     * 获取所有字典列表
     */
    @SaCheckPermission("system:user:list")
    @PostMapping("/listAll")
    public AjaxResult<Object> listAll() {
        return AjaxResult.success(baseService.selectAll());
    }

    @SaCheckPermission("system:user:list")
    @PostMapping("/list")
    public TableDataInfo<SysDictVo> listPage(SysDictBo bo, PageQuery pageQuery) {
        return baseService.selectPageList(bo, pageQuery);
    }


    /**
     * 获取用户详细信息
     *
     * @return
     */
    @SaCheckPermission("system:user:query")
    @GetMapping("/{id}")
    public AjaxResult<SysDictVo> queryById(@PathVariable Long id) {
        return success(baseService.selectVoById(id));
    }

    /**
     * 获取用户详细信息
     *
     * @return
     */
    @SaCheckPermission("system:user:edit")
    @PutMapping
    public AjaxResult<Boolean> edit(@Validated @RequestBody(required = false) SysDictBo bo) {
        return success(baseService.updateById(bo));
    }

    /**
     * 新增用户
     *
     * @return vo
     */
    @SaCheckPermission("system:user:insert")
    @PostMapping
    public AjaxResult<Boolean> insert(@Validated @RequestBody(required = false) SysDictBo bo) {
        return success(baseService.insert(bo));
    }

    /**
     * 删除用户
     *
     * @return vo
     */
    @SaCheckPermission("system:user:delete")
    @DeleteMapping("/{id}")
    public AjaxResult<Boolean> delete(@PathVariable Long id) {
        return success(baseService.deleteById(id));
    }


}
